from selenium.webdriver.common.by import By

from base.base_page import BasePage


class TpshopGoShopping(BasePage):

    def tpshop_login(self):
        self.get_url("http://hmshop-test.itheima.net/Home/user/login.html")
        self.element_send_keys(By.ID, "username", "13200000002")
        self.element_send_keys(By.ID, "password", "123456")
        self.element_send_keys(By.ID, "verify_code", "8888")
        self.element_click(By.CLASS_NAME, "J-login-submit")

    def buy_shop(self, goods):
        self.element_click(By.LINK_TEXT, "首页")
        self.element_send_keys(By.ID, "q", goods)
        self.element_click(By.CLASS_NAME, "ecsc-search-button")
        self.element_click(By.CLASS_NAME, "xs_img")
        self.element_click(By.ID, "join_cart")
        self.element_iframe(By.ID, "layui-layer-iframe1")
        self.element_click(By.CLASS_NAME, "ui-button-122")

    def settlement_shop(self):
        self.element_default()
        self.element_click(By.CLASS_NAME, "paytotal")
        self.element_alert_yes()
        self.element_send_keys(By.CLASS_NAME, "user_note_txt", "灭掉小日本")
        self.element_click(By.ID, "submit_order")
        self.element_click(By.CLASS_NAME, "button-confirm-payment")
        return self.element_text(By.CLASS_NAME, "erhuh")

    def order_success(self):
        self.tpshop_login()
        self.buy_shop("goods")
        return self.settlement_shop()



if __name__ == '__main__':
    a = TpshopGoShopping()
    a.order_success()